Imports System.Xml
Imports System.Data.SqlClient
Public Class dConexion
    Private Shared Function DBConnect() As SqlConnection
        Dim dts_XML As DataSet = New DataSet()
        dts_XML.ReadXml("C:\TESIS\TGB\TGB\Connexion.xml")
        'dts_XML.ReadXml("d:\ProyectoFinal\EitiSoft\TGB\TGB\Connexion.xml")
        Return New SqlConnection(dts_XML.Tables("Connection").Rows(0).Item("ConnectionString"))
    End Function
    Public Shared Function Consultar(ByVal NombreStore As String, ByVal Parametros As ArrayList) As DataSet
        Dim cnn As SqlConnection = DBConnect()
        cnn.Open()
        Dim cmd As SqlCommand = New SqlCommand()
        cmd.Connection = cnn
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = NombreStore
        cmd.Parameters.Clear()
        Dim i As Integer = 0
        For i = 0 To Parametros.Count - 1
            cmd.Parameters.Add(Parametros(i))
        Next
        Dim dta As SqlDataAdapter = New SqlDataAdapter(cmd)
        Dim dts As DataSet = New DataSet
        dta.Fill(dts)
        cnn.Close()
        Return dts
    End Function
    Public Shared Function ABM(ByVal Consulta As String, ByVal Parametros As ArrayList) As Boolean
        Dim okas As Boolean = False
        Dim cnn As SqlConnection = DBConnect()
        cnn.Open()
        Dim cmd As SqlCommand = New SqlCommand()
        cmd.Connection = cnn
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = Consulta
        cmd.Parameters.Clear()
        Dim i As Integer = 0
        For i = 0 To Parametros.Count - 1
            cmd.Parameters.Add(Parametros(i))
        Next
        Try
            okas = cmd.ExecuteNonQuery() <> 0
        Catch ex As Exception
            okas = False
        End Try
        cnn.Close()
        Return okas
    End Function
    
End Class
